home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Graphics & Imaging / Printer Drivers / Print Queue ƒ 1.1 / ModifyQueue.c next >
Encoding:
C/C++ Source or Header  |  1991-06-25  |  19.7 KB  |  955 lines  |  [TEXT/KAHL]

  1. /*
  2.         © Copyright 1989 Apple Computer, Inc.
  3.         
  4.         By Ricardo Batista
  5.         
  6.         
  7.         This file contains a code resource which is used within 4-Dimension
  8.         to provide print queue management whitin 4D in Macintosh Portables.
  9.         
  10.         The idea is that when the user launches 4D, we take PrintMonitor out
  11.         of the System Folder with a call to PrintQueue(), the effect of this is
  12.         that if the user prints something from 4D PrintMonitor will not be
  13.         launched and therefore it will not attempt to print and bother the user
  14.         with messages, the user is using a Portable Macintosh and may not be
  15.         connected to a network at the moment, therefore he just wants the print
  16.         outs to be spooled but he doesn't want PrintMonitor to bother him.
  17.         Once they quit 4D we restore the place of PrintMonitor.  If the user
  18.         goes to his office and connects to a network he'll want to print, for
  19.         this he selects a menu option of 4D and we will restore PrintMonitor
  20.         in the system folder so it is launched by Backgrounder.
  21.         
  22.         Notice that if the user selects the chooser to select a printer before
  23.         he tell us he wants to print, background printing will be disabled from
  24.         the chooser automatically by the laserwriter driver. (Maybe I'll do something
  25.         about that)
  26.         
  27.         The other function we provide is management of the print queue within
  28.         4D, to dot this our ModifyPrintQueue() is called, which shows the current
  29.         spooled files in a window, in this window we allow the user to change
  30.         the print order.  PrintMonitor uses the files named 'Spool File 1',
  31.         'Spool File 2', ...etc, to change the order all we need to do is rename
  32.         these files, the name used to print a file can be taken out of the resource
  33.         of each of these files, under 'STR ' -8189.
  34.         
  35.         Note: PrintMonitor prints the files based on their creation date, but we
  36.         like to change the name to make it easier for us.
  37.         
  38.         
  39.     HISTORY:
  40.     
  41.     08/25/89 RB    New Today
  42.     
  43.     
  44.     SPECIAL INSTRUCTIONS:
  45.     
  46.     Compile in THINK C as a code resource, give the resource a name that will be used
  47.     from 4D to call this external, then use 4D Ext Mover to copy into the Proc.Ext file
  48.     of the database to have print queue management.
  49.     
  50. */
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. #include "SetupA4.h"
  64.  
  65.  
  66.  
  67.  
  68. typedef struct {
  69.     int total;
  70.     long zero1;
  71.     Rect box1;
  72.     char type1;
  73.     char len1;
  74.     char name1[2];
  75.     long zero2;
  76.     Rect box2;
  77.     char type2;
  78.     char len2;
  79.     char name2[12];
  80.     long zero3;
  81.     Rect box3;
  82.     char type3;
  83.     char len3;
  84.     char name3[14];
  85.     long zero4;
  86.     Rect box4;
  87.     char type4;
  88.     char len4;
  89.     long zero5;
  90.     Rect box5;
  91.     char type5;
  92.     char len5;
  93.     char name5[12];
  94. } dItem;
  95.  
  96.  
  97.  
  98.  
  99. #define        okItem            1
  100. #define        upItem            2
  101. #define        downItem        3
  102. #define        listItem        4
  103.  
  104.  
  105. #define        cancelItem        2
  106.  
  107.  
  108. #define        ZoneDlg            16000
  109.  
  110.  
  111. #define        GetZoneList        0x8000000
  112. #define        GetMyZone        0x7000000
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. /*
  122.     This function extracts names and addresses out of a buffer filled by NBP
  123. */
  124.  
  125.  
  126. int myNBPExtract(buffer,howMany,which,Name,Addr)
  127. char *buffer;
  128. int howMany;
  129. int which;
  130. EntityName *Name;
  131. AddrBlock *Addr;
  132. {
  133.     char *p;
  134.     register int index = 1, nameCounter = 0;
  135.     
  136.     p = buffer;
  137.     while ((index < which) && (index < howMany)) {
  138.         p += 5;    /* skip addr and enumerator */
  139.         p += (*p) + 1;    /* skip name */
  140.         p += (*p) + 1;    /* skip type */
  141.         p += (*p) + 1;    /* skip zone */
  142.         index++;
  143.     }
  144.     BlockMove(p,Addr,4L);
  145.     p += 5;
  146.     BlockMove(p,Name->objStr,33L);
  147.     p += (*p) + 1;
  148.     BlockMove(p,Name->typeStr,33L);
  149.     p += (*p) + 1;
  150.     BlockMove(p,Name->zoneStr,33L);
  151.     return(0);
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. /*
  166.     This function fills in zone name with a default value, then if there are
  167.     any zone names we show them to the user and allow them to select one of these
  168.     zones.  Once a zone is selected we look for LaserWriters and we allow the user
  169.     to select one as the new destination printer.
  170.     If everything goes ok we return true (okItem), if user cancels we return
  171.     false (0).
  172. */
  173.  
  174.  
  175. Boolean GetAZone(char *zone, char *printerName)
  176. {
  177.     int abridge;
  178.     DialogPtr aDialog;
  179.     Point where;
  180.     ListHandle z;
  181.     int item,node,net,howMany,zones,err;
  182.     Rect zBox,bounds;
  183.     long ourData;
  184.     Point cell;
  185.     Handle H;
  186.     Boolean done = FALSE;
  187.     unsigned char dummy[4];
  188.     register int counter,index;
  189.     Ptr aBuf;
  190.     int datalen;
  191.     Boolean doubleClick;
  192.     DialogRecord d;
  193.     Rect box;
  194.     GrafPtr savePort;
  195.     ATPParamBlock a;
  196.     MPPParamBlock p;
  197.     BDSElement bds;
  198.     char Entity[100];
  199.     int howManyNames, nameCounter, nameIndex;
  200.     EntityName name;
  201.     AddrBlock tempAddr;
  202.     
  203.     SetCursor(*GetCursor(watchCursor));
  204.     zone[0] = 1;
  205.     zone[1] = '*';
  206.     asm {
  207.         move.l 0x2D8,a0
  208.         clr.w abridge
  209.         move.b 0x19(a0),abridge+1
  210.         move.w 0x1A(a0),net
  211.         clr.w node
  212.         move.b (a0),node+1
  213.     }
  214.     if (abridge == 0)
  215.         return(TRUE);
  216.     aBuf = NewPtr(2000L);
  217.     if (!aBuf) {
  218.         SysBeep(1);
  219.         return;
  220.     }
  221.     GetPort(&savePort);
  222.     aDialog = GetNewDialog(ZoneDlg,&d,-1L);
  223.     SetPort(aDialog);
  224.     GetDItem(aDialog,4,&item,&H,&zBox);
  225.     DrawDialog(aDialog);
  226.     SetRect(&bounds,0,0,0,0);
  227.     zBox.right -= 15;
  228.     cell.h = cell.v = 0;
  229.     z = LNew(&zBox,&bounds,cell,0,aDialog,TRUE,FALSE,FALSE,TRUE);
  230.     (*z)->selFlags |= lNoNilHilite + lNoRect + lNoExtend + lNoDisjoint + lOnlyOne;
  231.     zBox.top--;
  232.     zBox.left--;
  233.     zBox.right++;
  234.     zBox.bottom++;
  235.     LActivate(TRUE,z);
  236.     LAutoScroll(z);
  237.     LAddColumn(1,0,z);
  238.     FrameRect(&zBox);
  239.     howMany = zones = 0;
  240.     cell.v = cell.h = 0;
  241.     ourData = 0;
  242.     a.userData = GetZoneList;
  243.     a.atpFlags = 0;
  244.     a.addrBlock.aNode = abridge;
  245.     a.addrBlock.aNet = net;
  246.     a.addrBlock.aSocket = 6;
  247.     a.reqLength = 0;
  248.     a.reqPointer = 0L;
  249.     a.ATPnumOfBuffs = 1;
  250.     a.ATPtimeOutVal = 4;
  251.     a.ATPretryCount = 3;
  252.     a.bdsPointer = (Ptr) &bds;
  253.     bds.buffSize = 600;
  254.     bds.buffPtr = aBuf;
  255.     bds.dataSize = 0;
  256.     bds.userBytes = 0L;
  257.     aBuf[0] = 0;
  258.     ourData = 1;
  259.     FrameRect(&zBox);
  260.     zones = 0;
  261.     while (!done) {
  262.         ourData |= GetZoneList;
  263.         a.userData = ourData;
  264.         err = PSendRequest(&a,FALSE);
  265.         if (err) {
  266.             done = TRUE;
  267.             zones = 0;
  268.         }
  269.         BlockMove(&bds.userBytes,&dummy[0],4L);
  270.         BlockMove(&dummy[2],&howMany,2L);
  271.         zones += howMany;
  272.         ourData = zones;
  273.         if (!done) {
  274.             if (howMany)
  275.                 LAddRow(howMany,zones,z);
  276.             for (counter = 0, index = 0; counter < howMany; counter++) {
  277.                 LSetCell(&aBuf[index + 1],(int) aBuf[index],cell,z);
  278.                 cell.v++;
  279.                 index += aBuf[index] + 1;
  280.             }
  281.             FrameRect(&zBox);
  282.         }
  283.         if (!done)
  284.             done = dummy[0];
  285.     }
  286.     if (zones) {
  287.         a.userData = GetMyZone;
  288.         err = PSendRequest(&a,FALSE);
  289.         cell.v = cell.h = 0;
  290.         datalen = aBuf[0];
  291.         LSearch(&aBuf[1],datalen,0L,&cell,z);
  292.         LSetSelect(TRUE,cell,z);
  293.         LAutoScroll(z);
  294.     }
  295.     GetDItem(aDialog,okItem,&item,&H,&box);
  296.     PenSize(3,3);
  297.     InsetRect(&box,-4,-4);
  298.     FrameRoundRect(&box,16,16);
  299.     PenNormal();
  300.     if (zones) {
  301.         InitCursor();
  302.         item = cell.v = 0;
  303.         while ((item != okItem) && (item != cancelItem)) {
  304.             ModalDialog(0L,&item);
  305.             if (item == 4) {
  306.                 cell.v = 0;
  307.                 GetMouse(&where);
  308.                 if (LClick(where,0,z) && LGetSelect(TRUE,&cell,z))
  309.                     item = okItem;
  310.             }
  311.             if (item == okItem) {
  312.                 cell.v = cell.h = 0;
  313.                 if (!LGetSelect(TRUE,&cell,z)) {
  314.                     zone[0] = 1;
  315.                     zone[1] = '*';
  316.                 }
  317.                 else {
  318.                     datalen = 33;
  319.                     LGetCell(&(zone[1]),&datalen,cell,z);
  320.                     zone[0] = datalen;
  321.                 }
  322.             }
  323.         }
  324.     }
  325.     if (item == cancelItem) {
  326.         LDispose(z);
  327.         CloseDialog(aDialog);
  328.         SetPort(savePort);
  329.         DisposPtr(aBuf);
  330.         return(FALSE);
  331.     }
  332.                                 /* The user selected a zone, or there are no zones,
  333.                                         now let's find the LaserWriters' name     */
  334.     SetCursor(*GetCursor(watchCursor));
  335.     GetDItem(aDialog,3,&item,&H,&box);
  336.     SetIText(H,"\pPlease select a LaserWriter :");
  337.     howManyNames = (**z).dataBounds.bottom;
  338.     LDelRow(howManyNames,0,z);
  339.     BlockMove("\p=",Entity,2L);
  340.     nameIndex = Entity[0] + 1;
  341.     BlockMove("\pLaserWriter",&Entity[nameIndex],12L);
  342.     nameIndex += 12;
  343.     BlockMove(zone,&Entity[nameIndex],33L);
  344.     p.NBPinterval = 5;
  345.     p.NBPcount = 4;
  346.     p.NBPentityPtr = Entity;
  347.     p.NBPretBuffPtr = aBuf;
  348.     p.NBPretBuffSize = 2000;
  349.     p.NBPmaxToGet = 2000 / 110;
  350.     err = PLookupName(&p,FALSE);
  351.     howManyNames = p.NBPnumGotten;
  352.     cell.v = cell.h = 0;
  353.     if (howManyNames) {
  354.         nameCounter = 1;
  355.         while (nameCounter < (howManyNames + 1)) {
  356.             err = myNBPExtract(aBuf,howManyNames,nameCounter,&name,&tempAddr);
  357.             LAddRow(1,cell.v,z);
  358.             LSetCell(&(name.objStr[1]),(int) name.objStr[0],cell,z);
  359.             cell.v++;
  360.             nameCounter++;
  361.         }
  362.         InitCursor();
  363.         item = cell.v = 0;
  364.         while ((item != okItem) && (item != cancelItem)) {
  365.             ModalDialog(0L,&item);
  366.             if (item == 4) {
  367.                 cell.v = 0;
  368.                 GetMouse(&where);
  369.                 if (LClick(where,0,z) && LGetSelect(TRUE,&cell,z))
  370.                     item = okItem;
  371.             }
  372.             if (item == okItem) {
  373.                 cell.v = cell.h = 0;
  374.                 if (!LGetSelect(TRUE,&cell,z))
  375.                     item = cancelItem;
  376.                 else {
  377.                     datalen = 33;
  378.                     LGetCell(&(printerName[1]),&datalen,cell,z);
  379.                     printerName[0] = datalen;
  380.                 }
  381.             }
  382.         }
  383.     }
  384.     else
  385.         SysBeep(1);
  386.     LDispose(z);
  387.     CloseDialog(aDialog);
  388.     DisposPtr(aBuf);
  389.     SetPort(savePort);
  390.     InitCursor();
  391.     if (item == cancelItem)
  392.         return(FALSE);
  393.     return(TRUE);
  394. }
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409. /*
  410.     This function is called when the user double clicks on a print out name in the
  411.     print queue listing, it is used to allow the user to select a new printer for
  412.     that document, this is done because the user may have printed documents while
  413.     outside an office and didn't know what printer he was going to use, the spool
  414.     file already contains the name of a printer, and if the printer is not found
  415.     the document is lost, so here he has a chance to change the printer for a
  416.     given document. Good Stuff !
  417. */
  418.  
  419. void ChangeType(int index, ListHandle myList, int *volume, long *dirID)
  420. {
  421.     char zone[40], printerName[40];
  422.     Handle H;
  423.     int file;
  424.     char name[70];
  425.     Point cell;
  426.     int temp;
  427.     char num[10];
  428.     int len, counter;
  429.     long size;
  430.     
  431.     if (GetAZone(zone,printerName)) {
  432.         cell.h = 1;
  433.         cell.v = index;
  434.         len = 2;
  435.         LGetCell(&temp,&len,cell,myList);
  436.         BlockMove("\pSpool File ",name,12L);
  437.         NumToString((long) temp, (StringPtr) num);
  438.         BlockMove(&num[1],&name[12],3L);
  439.         name[0] += num[0];
  440.         file = HOpenResFile(*volume,*dirID,name,fsRdWrPerm);
  441.         if (file != -1) {
  442.             H = GetResource('PAPA',-8192);
  443.             if (H) {
  444.                 LoadResource(H);
  445.                 HLock(H);
  446.                 len = printerName[0] + 1;
  447.                 counter = 0;
  448.                 BlockMove(printerName,&((*H)[counter]),(long) len);
  449.                 counter += len;
  450.                 BlockMove("\pLaserWriter",&((*H)[counter]),12L);
  451.                 counter += 12;
  452.                 len = zone[0] + 1;
  453.                 BlockMove(zone,&((*H)[counter]),(long) len);
  454.                 counter += len;
  455.                 size = 0L;
  456.                 BlockMove(size,&((*H)[counter]),4L);
  457.                 HUnlock(H);
  458.                 ChangedResource(H);
  459.                 WriteResource(H);
  460.             }
  461.             H = GetResource('PREC',124);
  462.             if (H) {
  463.                 LoadResource(H);
  464.                 len = printerName[0] + 1;
  465.                 SetHandleSize(H,(long) len);
  466.                 HLock(H);
  467.                 BlockMove(printerName,*H,(long) len);
  468.                 HUnlock(H);
  469.                 ChangedResource(H);
  470.                 WriteResource(H);
  471.             }
  472.             CloseResFile(file);
  473.         }
  474.     }
  475. }
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491. /*
  492.     This function reads the new order of the spool files from the list and
  493.     make any adjustments as nessesary in order to print the items of the list
  494.     in the order the user has selected.  We do this by renaming the spool files
  495.     and changing the creation date.
  496. */
  497.  
  498. void AdjustQueue(ListHandle myList, int *volume, long *dirID)
  499. {
  500.     int err;
  501.     char name[70], num[10];
  502.     register int index, total;
  503.     CInfoPBRec info;
  504.     HFileParam p;
  505.     ioParam *io;
  506.     Boolean changed = FALSE;
  507.     int temp, len;
  508.     Point cell;
  509.     long time;
  510.     
  511.     total = (**myList).dataBounds.bottom;
  512.     if (!total)
  513.         return;
  514.     len = 2;
  515.     cell.h = 1;
  516.     cell.v = 0;
  517.     for (index = 0; index < total; index++) {
  518.         cell.v = index;
  519.         LGetCell(&temp,&len,cell,myList);
  520.         cell.v++;
  521.         if (cell.v != temp) {
  522.             changed = TRUE;
  523.             index = total;
  524.         }
  525.     }
  526.     if (!changed)
  527.         return;
  528.     time = Time;
  529.     BlockMove("\pSpool File ",name,12L);
  530.     p.ioCompletion = 0L;
  531.     p.ioVRefNum = *volume;
  532.     p.ioDirID = *dirID;
  533.     io = (ioParam*) &p;
  534.     p.ioNamePtr = (StringPtr) name;
  535.     io->ioMisc = (Ptr) num;
  536.     err = 0;
  537.     index = 1;
  538.     while (!err) {
  539.         NumToString((long) index, (StringPtr) num);
  540.         BlockMove(&num[1],&name[12],3L);
  541.         name[0] = 11 + num[0];
  542.         err = PBHRename(io,FALSE);
  543.         index++;
  544.     }
  545.     cell.h = 1;
  546.     len = 2;
  547.     info.hFileInfo.ioCompletion = 0L;
  548.     info.hFileInfo.ioVRefNum = *volume;
  549.     info.hFileInfo.ioDirID = *dirID;
  550.     p.ioNamePtr = (StringPtr) num;
  551.     io->ioMisc = (Ptr) name;
  552.     for (index = 0; index < total; index++) {
  553.         cell.v = index;
  554.         LGetCell(&temp,&len,cell,myList);
  555.         cell.v++;
  556.         NumToString((long) cell.v, (StringPtr) num);
  557.         BlockMove(&num[1],&name[12],3L);
  558.         name[0] = 11 + num[0];
  559.         NumToString((long) temp, (StringPtr) num);
  560.         err = PBHRename(io,FALSE);
  561.         info.hFileInfo.ioNamePtr = (StringPtr) name;
  562.         info.hFileInfo.ioFDirIndex = 0;
  563.         info.hFileInfo.ioFlAttrib = 0;
  564.         info.hFileInfo.ioFlFndrInfo.fdFlags = 0;
  565.         err = PBGetCatInfo(&info,FALSE);
  566.         info.hFileInfo.ioFlCrDat = time + temp;
  567.         info.hFileInfo.ioFDirIndex = 0;
  568.         err = PBSetCatInfo(&info,FALSE);
  569.     }
  570. }
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585. /*
  586.     This function reads the disk catalog and finds files called 'Spool File'
  587.     to add these to the list given to the function, the STR -8189 is put in
  588.     the list as the title of the print out.
  589.     We also set volume and dirID to the right values, which will be used in
  590.     other routines.
  591. */
  592.  
  593. void SpoolFill(ListHandle myList, int *volume, long *dirID)
  594. {
  595.     CInfoPBRec info;
  596.     WDPBRec wd;
  597.     int err;
  598.     char st[70], name[70];
  599.     register int index;
  600.     Point cell;
  601.     int file;
  602.     StringHandle H;
  603.     char num[10];
  604.     int temp;
  605.     SysEnvRec mac;
  606.     
  607.     LAddColumn(1,1,myList);
  608.     wd.ioCompletion = 0L;
  609.     wd.ioWDIndex = 0;
  610.     wd.ioVRefNum = BootDrive;
  611.     wd.ioNamePtr = 0L;
  612.     wd.ioWDProcID = 0;
  613.     err = PBGetWDInfo(&wd,FALSE);
  614.     info.dirInfo.ioCompletion = 0L;
  615.     if (mac.systemVersion < 0x700)
  616.         info.dirInfo.ioNamePtr = (StringPtr) "\pSpool Folder";
  617.     else
  618.         info.dirInfo.ioNamePtr = (StringPtr) "\pPrintMonitor Documents";
  619.     info.dirInfo.ioVRefNum = BootDrive;
  620.     info.dirInfo.ioFDirIndex = 0;
  621.     info.dirInfo.ioDrDirID = 0;
  622.     err = PBGetCatInfo(&info,FALSE);
  623.     if (err == fnfErr)
  624.         return;
  625.     *dirID = info.dirInfo.ioDrDirID;
  626.     *volume = wd.ioWDVRefNum;
  627.     index = 1;
  628.     info.dirInfo.ioCompletion = 0L;
  629.     info.dirInfo.ioNamePtr = (StringPtr) st;
  630.     cell.h = cell.v = 0;
  631.     LDoDraw(FALSE,myList);
  632.     BlockMove("\pSpool File ",st,12L);
  633.     file = 0;
  634.     while (file != -1) {
  635.         NumToString((long) index, (StringPtr) num);
  636.         BlockMove(&num[1],&st[12],3L);
  637.         st[0] = 11 + num[0];
  638.         file = HOpenResFile(*volume,*dirID,st,fsRdPerm);
  639.         if (file != -1) {
  640.             H = GetString(-8189);
  641.             if (H) {
  642.                 LoadResource(H);
  643.                 HLock(H);
  644.                 BlockMove(*H,name,60L);
  645.                 HUnlock(H);
  646.                 ReleaseResource(H);
  647.             }
  648.             if (name[0] == 0)
  649.                 BlockMove("\pUntitled",name,9L);
  650.             CloseResFile(file);
  651.             LAddRow(1,index - 1,myList);
  652.             cell.h = 0;
  653.             LSetCell(&name[1],(int) name[0],cell,myList);
  654.             cell.h = 1;
  655.             temp = cell.v + 1;
  656.             LSetCell(&temp,2,cell,myList);
  657.             cell.v++;
  658.         }
  659.         index++;
  660.     }
  661.     LDoDraw(TRUE,myList);
  662. }
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674. /*
  675.     This function creates a DITL (dialog item list) in memory so we can use
  676.     ModalDialog with our dialog, this is because we don't want the user to click
  677.     on other windows while he is changing the order of the spool files, specially
  678.     with MultiFinder.  We create the DITL based on the structure we have defined
  679.     at the begining of this file, we first create the ok button, move to top,
  680.     move to bottom and user item for the list.
  681.     NOTE:
  682.     At this time we didn't know if we could use resources in a 4D external.
  683. */
  684.  
  685. dItem** MakeDITL(bounds)
  686. Rect bounds;
  687. {
  688.     dItem ** items;
  689.     Rect box;
  690.     
  691.     bounds.right -= bounds.left;
  692.     bounds.left = 0;
  693.     bounds.bottom -= bounds.top;
  694.     bounds.top = 0;
  695.     
  696.     items = (dItem**) NewHandle(sizeof(dItem));
  697.     if (!items)
  698.         return(0L);
  699.     HLock(items);
  700.     (**items).total = 4;
  701.     
  702.     (**items).zero1 = 0L;
  703.     (**items).type1 = ctrlItem + btnCtrl;
  704.     (**items).len1 = 2;
  705.     BlockMove("OK",(**items).name1,2L);
  706.     box.top = bounds.bottom - 30;
  707.     box.bottom = box.top + 20;
  708.     box.right = bounds.right - 22;
  709.     box.left = box.right - StringWidth("\pOKOK") - 20;
  710.     (**items).box1 = box;
  711.     
  712.     (**items).zero2 = 0L;
  713.     (**items).type2 = ctrlItem + btnCtrl;
  714.     (**items).len2 = 12;
  715.     BlockMove("Move to top ",(**items).name2,12L);
  716.     box.right = box.left - 15;
  717.     box.left = box.right - StringWidth("\pMove to bottom") - 20;
  718.     (**items).box2 = box;
  719.     
  720.     (**items).zero3 = 0L;
  721.     (**items).type3 = ctrlItem + btnCtrl;
  722.     (**items).len3 = 14;
  723.     BlockMove("Move to bottom",(**items).name3,14L);
  724.     box.right = box.left - 15;
  725.     box.left = box.right - StringWidth("\pMove to bottom") - 20;
  726.     (**items).box3 = box;
  727.     
  728.     (**items).zero4 = 0L;
  729.     (**items).type4 = userItem;
  730.     (**items).len4 = 0;
  731.     box.top = 50;
  732.     box.left = 20;
  733.     box.right = bounds.right - 20;
  734.     box.bottom = bounds.bottom - 50;
  735.     (**items).box4 = box;
  736.     
  737.     (**items).zero5 = 0L;
  738.     (**items).type5 = statText;
  739.     (**items).len5 = 12;
  740.     BlockMove("Print Queue:",(**items).name5,12L);
  741.     box.top = 14;
  742.     box.bottom = box.top + 16;
  743.     box.left = 20;
  744.     box.right = 200;
  745.     (**items).box5 = box;
  746.     
  747.     HUnlock(items);
  748.     return(items);
  749. }
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763. /*
  764.     This is the main function of this 4D external command, we receive no
  765.     parameters, we first create the spool queue window and get the names
  766.     from the files in the Spool Folder, after the user closes our window
  767.     we rename some files as nessesary. (And change creation date)
  768. */
  769.  
  770.  
  771. pascal void main(void)
  772. {
  773.     DialogPtr myDialog;
  774.     DialogRecord dRec;
  775.     Rect box;
  776.     int err = 0, item = 0;
  777.     Rect listRect, bounds, okRect;
  778.     dItem** items;
  779.     ListHandle myList;
  780.     GrafPtr savePort;
  781.     Point cell, where;
  782.     ControlHandle top, bottom;
  783.     char st[100];
  784.     int number, len, total;
  785.     Boolean changed = TRUE;
  786.     int volume;
  787.     long dirID;
  788.     
  789.     /* InitAll(); */
  790.     RememberA0();
  791.     SetUpA4();
  792.     GetPort(&savePort);
  793.     box.top = 70;
  794.     box.bottom = box.top + 254;
  795.     box.left = 40;
  796.     box.right = box.left + 380;
  797.     items = MakeDITL(box);
  798.     if (!items) {
  799.         SysBeep(1);
  800.         return;
  801.     }
  802.     okRect = (**items).box1;
  803.     listRect = (**items).box4;
  804.     myDialog = NewDialog(&dRec,&box,"\pPrint Queue",1,dBoxProc,-1L,0,0L,items);
  805.     SetPort(myDialog);
  806.     SetRect(&bounds,0,0,1,0);
  807.     cell.h = cell.v = 0;
  808.     listRect.right -= 16;
  809.     myList = LNew(&listRect,&bounds,cell,0,myDialog,1,0,0,1);
  810.     (**myList).selFlags = lNoNilHilite + lNoRect + lNoExtend + lNoDisjoint + lOnlyOne;
  811.     LActivate(TRUE,myList);
  812.     SpoolFill(myList,&volume,&dirID);
  813.     DrawDialog(myDialog);
  814.     LAutoScroll(myList);
  815.     LUpdate(myDialog->visRgn,myList);
  816.     InsetRect(&listRect,-1,-1);
  817.     FrameRect(&listRect);
  818.     GetDItem(myDialog,upItem,&item,&top,&bounds);
  819.     GetDItem(myDialog,downItem,&item,&bottom,&bounds);
  820.     total = (**myList).dataBounds.bottom;
  821.     if (total == 0) {
  822.         HiliteControl(top,255);
  823.         HiliteControl(bottom,255);
  824.     }
  825.     InsetRect(&okRect,-4,-4);
  826.     PenSize(3,3);
  827.     FrameRoundRect(&okRect,16,16);
  828.     PenNormal();
  829.     item = 0;
  830.     InitCursor();
  831.     while (item != okItem) {
  832.         if (changed) {
  833.             cell.h = cell.v = 0;
  834.             if (LGetSelect(TRUE,&cell,myList)) {
  835.                 HiliteControl(top,0);
  836.                 HiliteControl(bottom,0);
  837.             }
  838.             else {
  839.                 HiliteControl(top,255);
  840.                 HiliteControl(bottom,255);
  841.             }
  842.             changed = FALSE;
  843.         }
  844.         ModalDialog(0L,&item);
  845.         if (item == listItem) {
  846.             GetMouse(&where);
  847.             if (LClick(where,0,myList)) {
  848.                 cell.v = cell.h = 0;
  849.                 if (LGetSelect(TRUE,&cell,myList)) {
  850.                     ChangeType(cell.v,myList,&volume,&dirID);
  851.                     DrawDialog(myDialog);
  852.                     LUpdate(myDialog->visRgn,myList);
  853.                     PenSize(3,3);
  854.                     FrameRoundRect(&okRect,16,16);
  855.                     PenNormal();
  856.                     FrameRect(&listRect);
  857.                 }
  858.             }
  859.             changed = TRUE;
  860.         }
  861.         if (item == upItem) {
  862.             cell.v = cell.h = 0;
  863.             if (LGetSelect(TRUE,&cell,myList) && cell.v) {
  864.                 cell.h = 0;
  865.                 len = 64;
  866.                 LGetCell(&st[1],&len,cell,myList);
  867.                 st[0] = len;
  868.                 cell.h = 1;
  869.                 len = 2;
  870.                 LGetCell(&number,&len,cell,myList);
  871.                 LDelRow(1,cell.v,myList);
  872.                 LAddRow(1,0,myList);
  873.                 cell.v = cell.h = 0;
  874.                 len = st[0];
  875.                 LSetCell(&st[1],len,cell,myList);
  876.                 len = 2;
  877.                 cell.h = 1;
  878.                 LSetCell(&number,len,cell,myList);
  879.                 changed = TRUE;
  880.             }
  881.         }
  882.         if (item == downItem) {
  883.             cell.v = cell.h = 0;
  884.             if (LGetSelect(TRUE,&cell,myList) && (cell.v != (total - 1))) {
  885.                 cell.h = 0;
  886.                 len = 64;
  887.                 LGetCell(&st[1],&len,cell,myList);
  888.                 st[0] = len;
  889.                 cell.h = 1;
  890.                 len = 2;
  891.                 LGetCell(&number,&len,cell,myList);
  892.                 LDelRow(1,cell.v,myList);
  893.                 LAddRow(1,total - 1,myList);
  894.                 cell.v = total - 1;
  895.                 cell.h = 0;
  896.                 len = st[0];
  897.                 LSetCell(&st[1],len,cell,myList);
  898.                 len = 2;
  899.                 cell.h = 1;
  900.                 LSetCell(&number,len,cell,myList);
  901.                 changed = TRUE;
  902.             }
  903.         }
  904.     }
  905.     AdjustQueue(myList,&volume,&dirID);
  906.     LDispose(myList);
  907.     CloseDialog(myDialog);
  908.     SetPort(savePort);
  909.     RestoreA4();
  910.     return;
  911.     asm {
  912.         dc.b "© Copyright 1989 Apple Computer, Inc. By Ricardo Batista"
  913.     }
  914. }
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.